
package org.vestbjergbyggecenter.Model;

import java.util.ArrayList;
import java.util.Calendar;

public class Order{
	private int id;
	//private ArrayList<SubOrder> subOrders;
	private ArrayList<Product> products;
	private long orderingDate;
	private long deliveryDate;
	private String status;
	private Customer customerId;
	private SalesAssistant salesAssistantId;
	private double totalPrice;
	
	public Order(int id, long deliveryDate, String status,
			Customer customerId, SalesAssistant assistantId) {
		this.id = id;
		this.orderingDate = getCurrentDate();
		this.deliveryDate = deliveryDate;
		this.status = status;
		this.customerId = customerId;
		this.salesAssistantId = assistantId;
		products = new ArrayList<>();
		//subOrders = new ArrayList<>();
	}

/*	public ArrayList<SubOrder> getSubOrders() {
		return subOrders;
	}
	
	public void addSubOrder(SubOrder subOrder)
	{
		subOrders.add(subOrder);
	}*/

	public ArrayList<Product> getProducts() {
		return products;
	}

	public void setProducts(ArrayList<Product> products) {
		this.products = products;
	}

	public void addProduct(Product product)
	{
		products.add(product);		
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public long getOrderingDate() {
		return orderingDate;
	}

	public void setOrderingDate(long orderingDate) {
		this.orderingDate = getCurrentDate();
	}

	public long getDeliveryDate() {
		return deliveryDate;
	}

	public void setDeliveryDate(long deliveryDate) {
		this.deliveryDate = deliveryDate;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public double getTotalPrice() {
		return totalPrice;
	}
	
	public Customer getCustomer() {
		return customerId;
	}
	public void setCustomer(Customer customer) {
		this.customerId = customer;
	}
	
	public SalesAssistant getSalesAssistant() {
		return salesAssistantId;
	}

	public void setSalesAssistantId(SalesAssistant salesAssistantId) {
		this.salesAssistantId = salesAssistantId;
	}
	
	public int getMonth(long orderingDate) {
		String b = String.valueOf(orderingDate);
		String c = b.substring(2, 4);
		int d = Integer.parseInt(c);
		return d;
	}
	
	public int getYear(long orderingDate) {
		String b = String.valueOf(orderingDate);
		String c = b.substring(4, 6);
		int d = Integer.parseInt(c);
		return d;
	}
	
	public long getCurrentDate()
    {
        Calendar cal = Calendar.getInstance();
        java.util.Date utilDate = cal.getTime();
        return utilDate.getTime();
    }
	
	public void print()
	{
		System.out.println("Id: " + id);
		System.out.println("Products: ");
		/*for(SubOrder subOrder : subOrders)
		{
			subOrder.print();
		}*/
		for(Product product : products)
		{
			product.print();
		}
		System.out.println("Orderding date: " + orderingDate);
		System.out.println("Delivery date: " + deliveryDate);
		System.out.println("Status: "+status);
		System.out.println("Total price: "+totalPrice);
	}
	
	public void printShort()
	{
		System.out.println("Id: " + id);
		System.out.println("Status: "+status);
		System.out.println("Total price: "+totalPrice);
	}
	
}
